subnauticafandomcom_pl-20200215-history
Moduł:Receptury
local p = {} -- Construct a display options table out of arguments local function construct_display_options (templateArgs) -- KEYWORDS: htmlgen modules local _htmlgen_default = 'tabela' local _htmlgen_mods = { 'równania' = 'Moduł:Receptury/Html', 'tabela' = 'Moduł:Receptury/Html2' } -- KEYWORDS: display options return { "htmlgen" = require ( _htmlgen_mods[ templateArgs'styl' or _htmlgen_default ] or _htmlgen_mods_htmlgen_default ), "hideFromCategories" = templateArgsto wystąpienie w kategoriach" 'tak', "features" = { -- KEYWORDS: display features "machineHeaders" = true, "machineSubcategories" = false, "collapsible" = true } } end -- Show a single recipe. -- KEYWORDS: function single recipe -- single recipe function p.show_single_recipe(frame) local templateArgs = frame:getParent().args local recipeTableQueries = require ('Module:Receptury/Odpytywanie') local _requestedItem = templateArgs"przedmiotu" local _displayOptions = construct_display_options (templateArgs) return recipeTableQueries.findItemRecipe (_requestedItem, _displayOptions) end -- Show all recipes made with an ingredient. -- KEYWORDS: function ingredient by function p.show_recipes_by_ingredient(frame) local templateArgs = frame:getParent().args local recipeTableQueries = require ('Module:Receptury/Odpytywanie') local _ingredient = templateArgsskładnik" local _displayOptions = construct_display_options (templateArgs) _displayOptions"tableHeader" = 'Przedmioty tworzone z użyciem: ' .. _ingredient return recipeTableQueries.findRecipesByCondition ( -- Search filter function ( itemName, itemRecipe, additionalFilterData ) for __ingredient, _ in pairs(itemRecipe"składniki") do if __ingredient:lower() additionalFilterData:lower() then return true end end return false end, _ingredient, -- Callback function ( recipeTable, itemCount, itemList, displayOptions ) local _htmlgen = displayOptions"htmlgen" return _htmlgen.construct_item_list ( recipeTable, itemList, displayOptions ) end, _displayOptions ) end -- Show all recipes made with a specific machine. -- KEYWORDS: function machine by function p.show_recipes_by_machine(frame) local templateArgs = frame:getParent().args local recipeTableQueries = require ('Module:Receptury/Odpytywanie') local _machine = templateArgsmaszynę" local _displayOptions = construct_display_options (templateArgs) return recipeTableQueries.findRecipesByCondition ( -- Search filter function (itemName, itemRecipe, additionalFilterData) return itemRecipe"urządzenie" additionalFilterData end, _machine, -- Callback function ( recipeTable, itemCount, itemList, displayOptions ) local _htmlgen = displayOptions"htmlgen" return _htmlgen.construct_item_list ( recipeTable, itemList, displayOptions ) end, _displayOptions ) end -- Dispatch the invocation to a proper function, based -- on the arguments. -- KEYWORDS: function dispatch auto function p.auto(frame) local templateArgs = frame:getParent().args if templateArgs"przedmiotu" ~= nil then return p.show_single_recipe (frame) elseif templateArgsskładnik" ~= nil then return p.show_recipes_by_ingredient (frame) elseif templateArgsmaszynę" ~= nil then return p.show_recipes_by_machine (frame) else return '' .. 'Nieprawidłowe użycie modułu. Dokumentacja szablonu.' .. '' .. (templateArgsto wystąpienie w kategoriach" ~= 'tak' and 'Kategoria:Artykuły z błędami modułu receptur' or '') end end function p.list(frame) local recipeTableQueries = require ('Module:Receptury/Odpytywanie') local args = frame:getParent().args local templateOptions = { "findSingle" = args"przedmiotu", "findIngredient" = argsskładnik", "findMachine" = argsmaszynę", "findEverything" = args"wszystko", "findByTag" = argspo tagu", "hideFromCategories" = argsto wystąpienie w kategoriach", "displayOptions" = { "machineHeaders" = true, "machineSubcategories" = false, "collapsible" = true } } -- Throw an error if there are no filters at all if templateOptions"findSingle" nil and templateOptions"findIngredient" nil and templateOptions"findMachine" nil and templateOptions"findByTag" nil and templateOptions"findEverything" nil then return '' .. 'Nieprawidłowe użycie modułu. Dokumentacja szablonu.' .. '' .. (templateOptions"hideFromCategories" ~= 'tak' and 'Kategoria:Artykuły z błędami modułu receptur' or '') end -- Check if a single recipe is requested and -- return it if templateOptions"findSingle" ~= nil then return recipeTableQueries.findItemRecipe (templateOptions"findSingle", filterData) end -- Alter display options if templateOptions"findMachine" ~= nil then templateOptions"displayOptions""machineHeaders" = false templateOptions"displayOptions""machineSubcategories" = true end -- Return recipes as a HTMl string return recipeTableQueries.findRecipesByCondition ( -- Custom filter that checks the filter data -- and combines required filters function (item, recipe, filterData) if templateOptions"findEverything" "tak" then return true end local finalResult = true if templateOptions"findByTag" nil and recipe"tag" ~= nil then return false end if templateOptions"findByTag" ~= nil and recipe"tag" ~= filterData"findByTag" then return false end if templateOptions"findIngredient" ~= nil then finalResult = finalResult and recipeTableQueries.filter_HasIngredient( item, recipe, templateOptions"findIngredient" ) end if templateOptions"findMachine" ~= nil then finalResult = finalResult and recipeTableQueries.filter_UsesMachine( item, recipe, templateOptions"findMachine" ) end return finalResult end, templateOptions, -- Ustawienia wyświetlania templateOptions"displayOptions" ) end return p